package com.dzsw.controller;

import com.dzsw.aspect.Neo4jAspect;
import com.dzsw.entity.Dept;
import com.dzsw.entity.RelationShip;
import com.dzsw.service.IBizService;
import com.dzsw.utils.DateUtil;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author sunz
 * @version 1.0
 * @CreateTime 2021-04-26-16:23
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private IBizService bizService;

    /**
     * CEO
     *    -设计部
     *        - 设计1组
     *        - 设计2组
     *    -技术部
     *        - 前端技术部
     *        - 后端技术部
     *        - 测试技术部
     */
    @GetMapping("/create")
    public String create(){
        bizService.create();
        return "create ok";
    }

    @GetMapping("/get/relationship")
    public RelationShip getRelationShipById(Long id){
        return bizService.getRelationShipById(id);
    }

    @GetMapping("/get/dept")
    public Dept getDeptById(Long id){
        return bizService.getDeptById(id);
    }

    @GetMapping("deleteRelationShip")
    public String deleteRelationShip(Long id){
        bizService.deleteRelationShip(id);
        return "delete relationShip ok";
    }

    @GetMapping("deleteDept")
    public String deleteDept(Long id){
        bizService.deleteDept(id);
        return "delete department ok";
    }

    @GetMapping("deleteAll")
    public String deleteAll(){
        bizService.deleteAll();
        return "delete all ok";
    }

    @Resource
    private Neo4jAspect aspectDemo;

    @GetMapping("/get/num")
    public String getNum() {
        aspectDemo.printGood();
        return bizService.getNum(null, 988) + "";
    }


    @GetMapping("/get/data")
    @Cacheable(value = "c_3", key = "'dzsw:test:mapkey'")
    public Map<String, Object> getData() {
        return doGenData();
    }

    @GetMapping("/cache/data")
    @CachePut(value = "c_3", key = "'dzsw:test:mapkey'")
    public Map<String, Object> cacheData() {
        return doGenData();
    }

    public Map<String, Object> doGenData() {
        Map<String, Object> resultMap = new HashMap<>();
        for (int i = 0; i < 20; i++) {
            resultMap.put("cache" + i, DateUtil.nowLdt());
        }
        return resultMap;
    }
}
